package com.Data;


import android.os.AsyncTask;
import com.SoapClasses.SoapPost_Tags;


public class Tag extends AsyncTask<Integer, String, Tag[]> {

    public static final int ACTION_GET_POPULAR = 20;

    public static final int ACTION_SEARCH = 10;

    private onGetPopularTagsCompleted callbackGetPopularTags;

    private onSearchTagCompleted callbackSearch;

    private int Count;

    private String Name;

    public interface onGetPopularTagsCompleted {

        void Completed(String result);
    }

    public interface onSearchTagCompleted {

        void Completed(Tag[] result);
    }

    public onGetPopularTagsCompleted getCallbackGetPopularTags() {

        return callbackGetPopularTags;
    }

    public onSearchTagCompleted getCallbackSearch() {

        return callbackSearch;
    }

    public int getCount() {

        return this.Count;
    }

    public String getName() {

        return Name;
    }

    public void setCallbackGetPopularTags(onGetPopularTagsCompleted callbackGetPopularTags) {

        this.callbackGetPopularTags = callbackGetPopularTags;
    }

    public void setCallbackSearch(onSearchTagCompleted callbackSearch) {

        this.callbackSearch = callbackSearch;
    }

    public void setCount(int count) {

        this.Count = count;
    }

    public void setName(String name) {

        Name = name;
    }

    @Override
    protected Tag[] doInBackground(Integer... accion) {

        switch (accion[0]) {
            case ACTION_GET_POPULAR:
                return new SoapPost_Tags().getTagPopular();
            case ACTION_SEARCH:
                return new SoapPost_Tags().getTagByName(this.Name);
            default:
                return null;

        }

    }

    @Override
    protected void onPostExecute(Tag[] result) {

        if (callbackGetPopularTags != null)
            callbackGetPopularTags.Completed(result[0].getName());

        if (callbackSearch != null)
            callbackSearch.Completed(result);

    }

}
